<?php
class Core_Data_Mappers_Trainingcandidate extends Core_Data_Mappers_Abstract {
	protected $_modelclass = 'Core_Data_Models_Trainingcandidate';
	protected $_map = array("Trainingid"=>"trainingid","Userid"=>"userid","IsSelect"=>"choose");
	protected $_businessclass = "Core_Business_Trainingcandidate";
	
	public function exists($object) {
		$row = $this->getDbTable()->fetchRow(array("trainingid = ?"=>$object->Trainingid,"userid = ?"=>$object->Userid));
		if(isset($row))
			return true;
		else
			return false;
	}
	public function find($object) {
		$row = $this->getDbTable()->fetchRow(array("trainingid = ?"=>$object->Trainingid,"userid = ?"=>$object->Userid));
		if(isset($row))
			return $this->map($row);
		else
			return null;
	}
	public function add($object) {
		if(!$this->exists($object)) {
			$data = $this->reversemap($object);
			$this->getDbTable()->insert($data);
		}
	}
	
	public function edit($object) {
		if($this->exists($object)) {
			$data = $this->reversemap($object);
			unset($data['trainingid']);
			unset($data['userid']);
			$this->getDbTable()->update($data, array("trainingid = ?"=>$object->Trainingid,"userid = ?"=>$object->Userid));
		}
	}
	
}